<template>
    <rx-dialog @ok="cancel" :okText="$ti18('rxForm.closeBtn','关闭')" :isCancel="false">
        <rx-layout>
            <template #middle>
                <a-form ref="form" :model="mdl" :rules="rules" class="rx-a-form-vertical" layout="vertical">
                    <a-row>
                        <a-col :span="12">
                            <a-form-item :label="i18n('form.subject','记录标题')" name="subject">
                                {{ mdl.subject }}
                            </a-form-item>
                        </a-col>
                        <a-col :span="12">
                            <a-form-item :label="i18n('form.listName','列表名称')" name="listName">
                                {{ mdl.listName }}
                            </a-form-item>
                        </a-col>
                    </a-row>
                    <a-row>
                        <a-col :span="12">
                            <a-form-item :label="i18n('form.status','导入状态')" name="status">
                                <a-tag :color="statusMap[mdl.status]?statusMap[mdl.status].color:null">
                                    <span>{{ statusMap[mdl.status] ? statusMap[mdl.status].text : null }}</span>
                                </a-tag>
                            </a-form-item>
                        </a-col>
                        <a-col :span="12">
                            <a-form-item :label="i18n('form.createByName','创建人名称')" name="createByName">
                                {{ mdl.createByName }}
                            </a-form-item>
                        </a-col>
                    </a-row>
                    <a-row>
                        <a-col :span="24">
                            <a-form-item style="width:100%" :label="i18n('form.log','记录日志')" name="content">
                                <rx-grid ref="table"
                                         :data="contentAry"
                                         :hasPage="true"
                                         :columns="contentColumns"
                                         height="auto"
                                >
                                </rx-grid>
                            </a-form-item>
                        </a-col>
                    </a-row>
                </a-form>
            </template>
        </rx-layout>
    </rx-dialog>
</template>
<script>
import FormImportRecordApi from '@/common/api/form/formImportRecord'
import {RxDialog, BaseFormModel, RxGrid} from '@lowcode/jpaas-base-lib';


export default {
    name: 'FormImportRecordEdit',
    mixins: [BaseFormModel],
    components: {
        RxDialog,
        RxGrid
    },
    data() {
        return {
            statusMap: {
                1: {color: 'green', text: this.i18n('statusMap.success','成功')},
                0: {color: 'red', text: this.i18n('statusMap.fail','失败')},
                2: {color: 'orange', text: this.i18n('statusMap.importing','正在导入')}
            },
            contentAry: [],
            contentColumns: [
                {
                    title: this.i18n('form.batchGroup','批次组'),
                    field: 'index',
                    minWidth: 60
                },
                {
                    title: this.i18n('form.exeResult','执行结果'),
                    field: 'content',
                    minWidth: 200,
                    showOverflow:'title'
                },
            ]
        }
    },
    methods: {
        i18n(name,text,key){
            return this.$ti18(name,text,"FormImportRecord",key);
        },
        onload_(values) {
            if (values) {
                this.contentAry = JSON.parse(values.content || '[]').sort(function (a, b) {
                    return a['index'] - b['index'];
                });
            }
        },
        get(id) {
            return FormImportRecordApi.get(id);
        },

        save() {
            return FormImportRecordApi.save(this.mdl);
        },

    }
}
</script>
<style>
.relick a {
    margin-right: 10px;
}

</style>
